2023 Method
Changes 0
M

WorksharingUtils.CheckoutElements

Description:
Obtains ownership for the current user of as many specified elements as possible.
Remarks:

For best performance, checkout all elements in one big call, rather than many small calls.

Revit may check out additional elements that are needed to check out the elements you requested. For example, if you request an element that is in a group, Revit will check out the entire group.

When there comes a contention error when locking the central model, this API would wait and retry endlessly until getting the lock of the central model.

Overloads (2):
CheckoutElements(Document,ICollection[ElementId])
public static ICollection<ElementId> CheckoutElements(
	Document document,
	ICollection<ElementId> elementsToCheckout
)
Return Value ICollection<ElementId> The ids of all specified elements that are now owned (but possibly out of date), including all that were owned prior to the function call.
void CheckoutAllRooms(Document doc)
{
    FilteredElementCollector collector = new FilteredElementCollector(doc);
    ICollection<ElementId> rooms = collector.WherePasses(new RoomFilter()).ToElementIds();
    ICollection<ElementId> checkoutelements = WorksharingUtils.CheckoutElements(doc, rooms);
    TaskDialog.Show("Checked out elements", "Number of elements checked out: " + checkoutelements.Count);
}